using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SS;
using SS.dir;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using TVSGPP.bookGPP;
namespace TVSGPP.func
{
	public class frmProductsPlan : Form
	{
		private IContainer components = null;
		private GroupBox groupBox1;
		private System.Windows.Forms.Label label4;
		private DateTimePicker txttoDay;
		private System.Windows.Forms.Label label3;
		private DateTimePicker txtfromDay;
		private System.Windows.Forms.Label label1;
		private ComboBox cbbWareHouse;
		private DataGridView dgvProduct;
		private GroupBox groupBox2;
		private System.Windows.Forms.TextBox txtSearch;
		private System.Windows.Forms.Label label2;
		private Button btnExportToExcel;
		private Button btnPrint;
		private Button btnClose;
		private System.Windows.Forms.Label lblMsg;
		private DataGridViewTextBoxColumn productName;
		private DataGridViewTextBoxColumn productUnit;
		private DataGridViewTextBoxColumn numFirstBalancer;
		private DataGridViewTextBoxColumn ProductInputInTime;
		private DataGridViewTextBoxColumn ProductTotal;
		private DataGridViewTextBoxColumn ProductOutputInTime;
		private DataGridViewTextBoxColumn ProductYesNo;
		private DataGridViewTextBoxColumn ProductBalancer;
		private DataGridViewTextBoxColumn NumPlan;
		private DataGridView dgvListPlan;
		private ComboBox cbbTypeProducts;
		private Button btnMakePlan;
		private Button btnSave;
		private DataGridViewTextBoxColumn DateCreate;
		private DataGridViewTextBoxColumn PlanID;
		private ContextMenuStrip contextMenuStrip1;
		private ToolStripMenuItem mnuPrint;
		private ToolStripMenuItem mnuExportToExcel;
		private ToolStripSeparator toolStripSeparator1;
		private ToolStripMenuItem mnuDel;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private bool isPostback = false;
		private frmWaitting objW;
		private string currPlanID = "0";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			this.components = new Container();
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle7 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle8 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle9 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle10 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle11 = new DataGridViewCellStyle();
			this.groupBox1 = new GroupBox();
			this.cbbWareHouse = new ComboBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.txttoDay = new DateTimePicker();
			this.label3 = new System.Windows.Forms.Label();
			this.txtfromDay = new DateTimePicker();
			this.dgvProduct = new DataGridView();
			this.productName = new DataGridViewTextBoxColumn();
			this.productUnit = new DataGridViewTextBoxColumn();
			this.numFirstBalancer = new DataGridViewTextBoxColumn();
			this.ProductInputInTime = new DataGridViewTextBoxColumn();
			this.ProductTotal = new DataGridViewTextBoxColumn();
			this.ProductOutputInTime = new DataGridViewTextBoxColumn();
			this.ProductYesNo = new DataGridViewTextBoxColumn();
			this.ProductBalancer = new DataGridViewTextBoxColumn();
			this.NumPlan = new DataGridViewTextBoxColumn();
			this.groupBox2 = new GroupBox();
			this.txtSearch = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.btnExportToExcel = new Button();
			this.btnPrint = new Button();
			this.btnClose = new Button();
			this.lblMsg = new System.Windows.Forms.Label();
			this.dgvListPlan = new DataGridView();
			this.DateCreate = new DataGridViewTextBoxColumn();
			this.PlanID = new DataGridViewTextBoxColumn();
			this.contextMenuStrip1 = new ContextMenuStrip(this.components);
			this.mnuPrint = new ToolStripMenuItem();
			this.mnuExportToExcel = new ToolStripMenuItem();
			this.toolStripSeparator1 = new ToolStripSeparator();
			this.mnuDel = new ToolStripMenuItem();
			this.cbbTypeProducts = new ComboBox();
			this.btnMakePlan = new Button();
			this.btnSave = new Button();
			this.groupBox1.SuspendLayout();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			this.groupBox2.SuspendLayout();
			((ISupportInitialize)this.dgvListPlan).BeginInit();
			this.contextMenuStrip1.SuspendLayout();
			base.SuspendLayout();
			this.groupBox1.Controls.Add(this.cbbWareHouse);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.txttoDay);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txtfromDay);
			this.groupBox1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox1.Location = new Point(6, 6);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(614, 59);
			this.groupBox1.TabIndex = 40;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Điều kiện tìm kiếm";
			this.cbbWareHouse.Cursor = Cursors.Hand;
			this.cbbWareHouse.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbWareHouse.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.cbbWareHouse.FormattingEnabled = true;
			this.cbbWareHouse.Location = new Point(366, 21);
			this.cbbWareHouse.Name = "cbbWareHouse";
			this.cbbWareHouse.Size = new Size(237, 23);
			this.cbbWareHouse.TabIndex = 91;
			this.cbbWareHouse.SelectedIndexChanged += new EventHandler(this.cbbWareHouse_SelectedIndexChanged);
			this.label1.AutoSize = true;
			this.label1.Location = new Point(296, 24);
			this.label1.Name = "label1";
			this.label1.Size = new Size(69, 15);
			this.label1.TabIndex = 60;
			this.label1.Text = "Kho hàng : ";
			this.label4.AutoSize = true;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label4.Location = new Point(176, 24);
			this.label4.Name = "label4";
			this.label4.Size = new Size(11, 15);
			this.label4.TabIndex = 59;
			this.label4.Text = "-";
			this.txttoDay.CustomFormat = "dd/MM/yyyy";
			this.txttoDay.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txttoDay.Format = DateTimePickerFormat.Custom;
			this.txttoDay.Location = new Point(191, 21);
			this.txttoDay.Name = "txttoDay";
			this.txttoDay.Size = new Size(100, 21);
			this.txttoDay.TabIndex = 58;
			this.txttoDay.ValueChanged += new EventHandler(this.txttoDay_ValueChanged);
			this.label3.AutoSize = true;
			this.label3.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label3.Location = new Point(12, 24);
			this.label3.Name = "label3";
			this.label3.Size = new Size(57, 15);
			this.label3.TabIndex = 57;
			this.label3.Text = "Từ ngày :";
			this.txtfromDay.CustomFormat = "dd/MM/yyyy";
			this.txtfromDay.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtfromDay.Format = DateTimePickerFormat.Custom;
			this.txtfromDay.Location = new Point(73, 21);
			this.txtfromDay.Name = "txtfromDay";
			this.txtfromDay.Size = new Size(100, 21);
			this.txtfromDay.TabIndex = 56;
			this.txtfromDay.ValueChanged += new EventHandler(this.txtfromDay_ValueChanged);
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.productName,
				this.productUnit,
				this.numFirstBalancer,
				this.ProductInputInTime,
				this.ProductTotal,
				this.ProductOutputInTime,
				this.ProductYesNo,
				this.ProductBalancer,
				this.NumPlan
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new Point(185, 68);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle2.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.RowsDefaultCellStyle = dataGridViewCellStyle2;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(708, 490);
			this.dgvProduct.TabIndex = 41;
			this.productName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.productName.DataPropertyName = "productName";
			this.productName.HeaderText = "Tên thuốc";
			this.productName.MinimumWidth = 100;
			this.productName.Name = "productName";
			this.productName.ReadOnly = true;
			this.productName.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productUnit.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productUnit.DataPropertyName = "productUnit";
			this.productUnit.HeaderText = "Đơn vị tính";
			this.productUnit.MinimumWidth = 80;
			this.productUnit.Name = "productUnit";
			this.productUnit.ReadOnly = true;
			this.productUnit.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productUnit.Width = 80;
			this.numFirstBalancer.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.numFirstBalancer.DataPropertyName = "numFirstBalancer";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle3.Format = "N2";
			dataGridViewCellStyle3.NullValue = "2";
			this.numFirstBalancer.DefaultCellStyle = dataGridViewCellStyle3;
			this.numFirstBalancer.HeaderText = "Tồn đầu kỳ";
			this.numFirstBalancer.MinimumWidth = 90;
			this.numFirstBalancer.Name = "numFirstBalancer";
			this.numFirstBalancer.ReadOnly = true;
			this.numFirstBalancer.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.numFirstBalancer.Width = 90;
			this.ProductInputInTime.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductInputInTime.DataPropertyName = "ProductInputInTime";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle4.Format = "N2";
			dataGridViewCellStyle4.NullValue = "0";
			this.ProductInputInTime.DefaultCellStyle = dataGridViewCellStyle4;
			this.ProductInputInTime.HeaderText = "Nhập trong kỳ";
			this.ProductInputInTime.MinimumWidth = 90;
			this.ProductInputInTime.Name = "ProductInputInTime";
			this.ProductInputInTime.ReadOnly = true;
			this.ProductInputInTime.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductInputInTime.Width = 90;
			this.ProductTotal.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductTotal.DataPropertyName = "ProductTotal";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle5.Format = "N2";
			dataGridViewCellStyle5.NullValue = "0";
			this.ProductTotal.DefaultCellStyle = dataGridViewCellStyle5;
			this.ProductTotal.HeaderText = "Tổng số";
			this.ProductTotal.MinimumWidth = 90;
			this.ProductTotal.Name = "ProductTotal";
			this.ProductTotal.ReadOnly = true;
			this.ProductTotal.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductTotal.Width = 90;
			this.ProductOutputInTime.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductOutputInTime.DataPropertyName = "ProductOutputInTime";
			dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle6.Format = "N2";
			dataGridViewCellStyle6.NullValue = "0";
			this.ProductOutputInTime.DefaultCellStyle = dataGridViewCellStyle6;
			this.ProductOutputInTime.HeaderText = "Xuất trong kỳ";
			this.ProductOutputInTime.MinimumWidth = 90;
			this.ProductOutputInTime.Name = "ProductOutputInTime";
			this.ProductOutputInTime.ReadOnly = true;
			this.ProductOutputInTime.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductOutputInTime.Width = 90;
			this.ProductYesNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductYesNo.DataPropertyName = "ProductYesNo";
			dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle7.Format = "N2";
			dataGridViewCellStyle7.NullValue = "0";
			this.ProductYesNo.DefaultCellStyle = dataGridViewCellStyle7;
			this.ProductYesNo.HeaderText = "Thừa, thiếu";
			this.ProductYesNo.MinimumWidth = 90;
			this.ProductYesNo.Name = "ProductYesNo";
			this.ProductYesNo.ReadOnly = true;
			this.ProductYesNo.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductYesNo.Width = 90;
			this.ProductBalancer.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductBalancer.DataPropertyName = "ProductBalancer";
			dataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle8.Format = "N2";
			dataGridViewCellStyle8.NullValue = "0";
			this.ProductBalancer.DefaultCellStyle = dataGridViewCellStyle8;
			this.ProductBalancer.HeaderText = "Tồn cuối kỳ";
			this.ProductBalancer.MinimumWidth = 95;
			this.ProductBalancer.Name = "ProductBalancer";
			this.ProductBalancer.ReadOnly = true;
			this.ProductBalancer.Width = 95;
			this.NumPlan.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.NumPlan.DataPropertyName = "NumPlan";
			dataGridViewCellStyle9.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle9.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			dataGridViewCellStyle9.Format = "N0";
			dataGridViewCellStyle9.NullValue = "0";
			this.NumPlan.DefaultCellStyle = dataGridViewCellStyle9;
			this.NumPlan.HeaderText = "SL Dự trù";
			this.NumPlan.MinimumWidth = 95;
			this.NumPlan.Name = "NumPlan";
			this.NumPlan.ReadOnly = true;
			this.NumPlan.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.NumPlan.Width = 95;
			this.groupBox2.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox2.Controls.Add(this.txtSearch);
			this.groupBox2.Controls.Add(this.label2);
			this.groupBox2.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.groupBox2.Location = new Point(626, 6);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new Size(267, 59);
			this.groupBox2.TabIndex = 42;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Tìm kiếm theo thuôc";
			this.txtSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtSearch.Font = new Font("Arial", 9f);
			this.txtSearch.Location = new Point(82, 24);
			this.txtSearch.Name = "txtSearch";
			this.txtSearch.Size = new Size(168, 21);
			this.txtSearch.TabIndex = 1;
			this.txtSearch.TextChanged += new EventHandler(this.txtSearch_TextChanged);
			this.label2.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label2.BackColor = SystemColors.ButtonHighlight;
			this.label2.Font = new Font("Arial", 9f);
			this.label2.Location = new Point(7, 17);
			this.label2.Name = "label2";
			this.label2.Size = new Size(250, 34);
			this.label2.TabIndex = 0;
			this.label2.Text = " Tên thuốc : ";
			this.label2.TextAlign = ContentAlignment.MiddleLeft;
			this.btnExportToExcel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel.Enabled = false;
			this.btnExportToExcel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnExportToExcel.FlatStyle = FlatStyle.Flat;
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new Point(670, 566);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(104, 26);
			this.btnExportToExcel.TabIndex = 46;
			this.btnExportToExcel.Text = "Xuất File Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			this.btnPrint.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnPrint.Enabled = false;
			this.btnPrint.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnPrint.FlatStyle = FlatStyle.Flat;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new Point(540, 566);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(129, 26);
			this.btnPrint.TabIndex = 45;
			this.btnPrint.Text = "In bảng dự trù [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnPrint_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(787, 566);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(106, 26);
			this.btnClose.TabIndex = 44;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.lblMsg.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.lblMsg.BackColor = Color.White;
			this.lblMsg.ForeColor = Color.Red;
			this.lblMsg.Location = new Point(205, 165);
			this.lblMsg.Name = "lblMsg";
			this.lblMsg.Size = new Size(678, 24);
			this.lblMsg.TabIndex = 134;
			this.lblMsg.Text = "Không tin thấy thông tin liên quan !";
			this.lblMsg.TextAlign = ContentAlignment.MiddleCenter;
			this.lblMsg.Visible = false;
			this.dgvListPlan.AllowUserToAddRows = false;
			this.dgvListPlan.AllowUserToDeleteRows = false;
			this.dgvListPlan.AllowUserToOrderColumns = true;
			this.dgvListPlan.AllowUserToResizeColumns = false;
			this.dgvListPlan.AllowUserToResizeRows = false;
			dataGridViewCellStyle10.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle10.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvListPlan.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle10;
			this.dgvListPlan.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
			this.dgvListPlan.BackgroundColor = Color.White;
			this.dgvListPlan.BorderStyle = BorderStyle.Fixed3D;
			this.dgvListPlan.ColumnHeadersHeight = 26;
			this.dgvListPlan.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvListPlan.Columns.AddRange(new DataGridViewColumn[]
			{
				this.DateCreate,
				this.PlanID
			});
			this.dgvListPlan.ContextMenuStrip = this.contextMenuStrip1;
			this.dgvListPlan.Cursor = Cursors.Hand;
			this.dgvListPlan.EnableHeadersVisualStyles = false;
			this.dgvListPlan.Location = new Point(6, 68);
			this.dgvListPlan.MultiSelect = false;
			this.dgvListPlan.Name = "dgvListPlan";
			this.dgvListPlan.ReadOnly = true;
			this.dgvListPlan.RowHeadersVisible = false;
			this.dgvListPlan.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			dataGridViewCellStyle11.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvListPlan.RowsDefaultCellStyle = dataGridViewCellStyle11;
			this.dgvListPlan.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvListPlan.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvListPlan.Size = new Size(173, 526);
			this.dgvListPlan.TabIndex = 135;
			this.dgvListPlan.CellEnter += new DataGridViewCellEventHandler(this.dgvListPlan_CellEnter);
			this.DateCreate.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.DateCreate.DataPropertyName = "DateCreate";
			this.DateCreate.HeaderText = "Ngày lập";
			this.DateCreate.MinimumWidth = 100;
			this.DateCreate.Name = "DateCreate";
			this.DateCreate.ReadOnly = true;
			this.DateCreate.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.PlanID.DataPropertyName = "AutoItem";
			this.PlanID.HeaderText = "PlanID";
			this.PlanID.Name = "PlanID";
			this.PlanID.ReadOnly = true;
			this.PlanID.Visible = false;
			this.contextMenuStrip1.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.contextMenuStrip1.Items.AddRange(new ToolStripItem[]
			{
				this.mnuPrint,
				this.mnuExportToExcel,
				this.toolStripSeparator1,
				this.mnuDel
			});
			this.contextMenuStrip1.Name = "contextMenuStrip1";
			this.contextMenuStrip1.Size = new Size(162, 76);
			this.mnuPrint.Name = "mnuPrint";
			this.mnuPrint.Size = new Size(161, 22);
			this.mnuPrint.Text = "In bảng dự trù";
			this.mnuExportToExcel.Name = "mnuExportToExcel";
			this.mnuExportToExcel.Size = new Size(161, 22);
			this.mnuExportToExcel.Text = "Xuất file Excel";
			this.toolStripSeparator1.Name = "toolStripSeparator1";
			this.toolStripSeparator1.Size = new Size(158, 6);
			this.mnuDel.Name = "mnuDel";
			this.mnuDel.Size = new Size(161, 22);
			this.mnuDel.Text = "Xoá bảng dự trù";
			this.mnuDel.Click += new EventHandler(this.mnuDel_Click);
			this.cbbTypeProducts.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.cbbTypeProducts.DropDownStyle = ComboBoxStyle.DropDownList;
			this.cbbTypeProducts.FlatStyle = FlatStyle.Flat;
			this.cbbTypeProducts.FormattingEnabled = true;
			this.cbbTypeProducts.Items.AddRange(new object[]
			{
				"Tất cả loại thuốc",
				"Thuốc hướng tâm"
			});
			this.cbbTypeProducts.Location = new Point(184, 567);
			this.cbbTypeProducts.Name = "cbbTypeProducts";
			this.cbbTypeProducts.Size = new Size(165, 23);
			this.cbbTypeProducts.TabIndex = 137;
			this.btnMakePlan.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnMakePlan.Enabled = false;
			this.btnMakePlan.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnMakePlan.FlatStyle = FlatStyle.Flat;
			this.btnMakePlan.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnMakePlan.Location = new Point(355, 566);
			this.btnMakePlan.Name = "btnMakePlan";
			this.btnMakePlan.Size = new Size(87, 26);
			this.btnMakePlan.TabIndex = 138;
			this.btnMakePlan.Text = "Lập dự trù";
			this.btnMakePlan.UseVisualStyleBackColor = true;
			this.btnMakePlan.Click += new EventHandler(this.btnMakePlan_Click);
			this.btnSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnSave.Enabled = false;
			this.btnSave.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnSave.FlatStyle = FlatStyle.Flat;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new Point(443, 566);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(96, 26);
			this.btnSave.TabIndex = 139;
			this.btnSave.Text = "Lưu thông tin";
			this.btnSave.UseVisualStyleBackColor = true;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnMakePlan);
			base.Controls.Add(this.cbbTypeProducts);
			base.Controls.Add(this.dgvListPlan);
			base.Controls.Add(this.lblMsg);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.groupBox2);
			base.Controls.Add(this.dgvProduct);
			base.Controls.Add(this.groupBox1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			base.Name = "frmProductsPlan";
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "LẬP DỰ TRÙ THUỐC";
			base.Load += new EventHandler(this.frmFocusMind_Load);
			base.KeyDown += new KeyEventHandler(this.frmFocusMind_KeyDown);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			((ISupportInitialize)this.dgvProduct).EndInit();
			this.groupBox2.ResumeLayout(false);
			this.groupBox2.PerformLayout();
			((ISupportInitialize)this.dgvListPlan).EndInit();
			this.contextMenuStrip1.ResumeLayout(false);
			base.ResumeLayout(false);
		}
		public frmProductsPlan()
		{
			this.InitializeComponent();
		}
		private void frmFocusMind_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyData == Keys.Escape)
			{
				this.btnClose.PerformClick();
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmFocusMind_Load(object sender, EventArgs e)
		{
			this.cbbTypeProducts.SelectedIndex = 0;
			this.objFunc.LoadComboBoxStock("SELECT WareHouse_ID, UPPER(WareHouse_Name) AS Name FROM TabWareHouse ORDER BY WareHouse_Name", this.cbbWareHouse, "WareHouse_ID", "Name");
			this.getListPlan();
			this.isPostback = true;
		}
		private void getListPlan()
		{
			try
			{
				this.dgvProduct.DataSource = null;
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT TOP 100 AutoItem, DateCreate FROM [TabProductPlan] ORDER BY [DateCreate] DESC";
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
				sqlDataAdapter.SelectCommand = sqlCommand;
				DataSet dataSet = new DataSet();
				sqlDataAdapter.Fill(dataSet);
				this.dgvListPlan.AutoGenerateColumns = false;
				this.dgvListPlan.DataSource = dataSet.Tables[0];
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		private void detListPlan(string AutoItem)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "DELETE FROM [TabProductPlanDetail] WHERE [PlanID] = " + AutoItem;
				sqlCommand.ExecuteNonQuery();
				sqlCommand.CommandText = "DELETE FROM [TabProductPlan] WHERE [AutoItem] = " + AutoItem;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
			}
			catch
			{
			}
		}
		private void getListPlanDetail(string planID)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT * FROM [TabProductPlanDetail] WHERE PlanID = " + planID;
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();
				sqlDataAdapter.SelectCommand = sqlCommand;
				DataSet dataSet = new DataSet();
				sqlDataAdapter.Fill(dataSet);
				this.dgvProduct.AutoGenerateColumns = false;
				this.objTable = new DataTable();
				this.objTable = dataSet.Tables[0];
				this.dgvProduct.DataSource = dataSet.Tables[0];
				sqlConnection.Close();
				sqlConnection.Dispose();
				if (dataSet.Tables[0].Rows.Count > 0)
				{
					this.btnPrint.Enabled = true;
					this.btnExportToExcel.Enabled = true;
					this.mnuPrint.Enabled = true;
					this.mnuExportToExcel.Enabled = true;
				}
				else
				{
					this.btnPrint.Enabled = false;
					this.btnExportToExcel.Enabled = false;
					this.mnuPrint.Enabled = false;
					this.mnuExportToExcel.Enabled = false;
				}
			}
			catch
			{
			}
		}
		public void getData()
		{
			try
			{
				ThreadStart start = new ThreadStart(this.showWatting);
				Thread thread = new Thread(start);
				thread.Start();
				if (!thread.Join(150))
				{
					this.lblMsg.Visible = false;
					this.objTable = new DataTable();
					DataColumn column = new DataColumn("ProductName", typeof(string));
					DataColumn column2 = new DataColumn("ProductUnit", typeof(string));
					DataColumn column3 = new DataColumn("numFirstBalancer", typeof(float));
					DataColumn column4 = new DataColumn("ProductInputInTime", typeof(float));
					DataColumn column5 = new DataColumn("ProductTotal", typeof(float));
					DataColumn column6 = new DataColumn("ProductOutputInTime", typeof(float));
					DataColumn column7 = new DataColumn("ProductYesNo", typeof(float));
					DataColumn column8 = new DataColumn("ProductBalancer", typeof(float));
					DataColumn column9 = new DataColumn("NumPlan", typeof(string));
					this.objTable.Columns.Add(column);
					this.objTable.Columns.Add(column2);
					this.objTable.Columns.Add(column3);
					this.objTable.Columns.Add(column4);
					this.objTable.Columns.Add(column5);
					this.objTable.Columns.Add(column6);
					this.objTable.Columns.Add(column7);
					this.objTable.Columns.Add(column8);
					this.objTable.Columns.Add(column9);
					string text = this.cbbWareHouse.SelectedValue.ToString();
					if (text != "0")
					{
						text = " AND [WID] = '" + text + "'";
					}
					else
					{
						text = " ";
					}
					string str = "";
					if (this.txtSearch.Text.Trim() != "")
					{
						str = " AND ProductName LIKE N'%" + this.txtSearch.Text.Trim() + "%' ";
					}
					SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
					sqlConnection.Open();
					SqlParameter sqlParameter = new SqlParameter("objDate0", SqlDbType.DateTime);
					SqlParameter sqlParameter2 = new SqlParameter("objDate1", SqlDbType.DateTime);
					SqlParameter sqlParameter3 = new SqlParameter("objDate2", SqlDbType.DateTime);
					sqlParameter.Value = DateTime.Parse(this.txtfromDay.Value.AddDays(-750.0).ToString().Substring(0, 10) + " 00:00:00 AM");
					sqlParameter2.Value = DateTime.Parse(this.txtfromDay.Value.ToString().Substring(0, 10) + " 00:00:00 AM");
					sqlParameter3.Value = DateTime.Parse(this.txttoDay.Value.ToString().Substring(0, 10) + " 11:59:59 PM");
					SqlCommand sqlCommand = sqlConnection.CreateCommand();
					sqlCommand.Parameters.Add(sqlParameter);
					sqlCommand.Parameters.Add(sqlParameter2);
					sqlCommand.Parameters.Add(sqlParameter3);
					if (this.cbbTypeProducts.SelectedIndex == 0)
					{
						sqlCommand.CommandText = "SELECT DISTINCT TabDetailBill.PID, TabDetailBill.ProductName,productUnit, NationalID, ISNULL([dbo].[uf_GetnumFirstBalancer](TabDetailBill.PID,WID,@objDate0,@objDate1),0) AS numFirstBalancer, ISNULL([dbo].[uf_GetnumInputInTime](TabDetailBill.PID, WID, @objDate1, @objDate2),0) AS InputInTime, ISNULL([dbo].[uf_GetnumOutputInTime](TabDetailBill.PID,WID, @objDate1, @objDate2),0) AS OutputInTime, [dbo].[uf_GetnumMaxBalancer]([TabDetailBill].[Pid]) AS numMaxBalancer FROM [TabDetailBill], [TabBill] WHERE [TabDetailBill].[BillID] = [TabBill].[ID] " + text + " AND (TabBill.CreateDate BETWEEN @objDate1 AND @objDate2)" + str;
					}
					else
					{
						sqlCommand.CommandText = "SELECT DISTINCT TabDetailBill.PID, TabDetailBill.ProductName,productUnit, NationalID, ISNULL([dbo].[uf_GetnumFirstBalancer](TabDetailBill.PID,WID,@objDate0,@objDate1),0) AS numFirstBalancer, ISNULL([dbo].[uf_GetnumInputInTime](TabDetailBill.PID, WID, @objDate1, @objDate2),0) AS InputInTime, ISNULL([dbo].[uf_GetnumOutputInTime](TabDetailBill.PID,WID, @objDate1, @objDate2),0) AS OutputInTime, [dbo].[uf_GetnumMaxBalancer]([TabDetailBill].[Pid]) AS numMaxBalancer FROM [TabDetailBill], [TabBill] WHERE [TabDetailBill].[BillID] = [TabBill].[ID] " + text + " AND (TabDetailBill.PID IN (SELECT PID FROM TabProducts WHERE [FocusMind] = 1) AND (TabBill.CreateDate BETWEEN @objDate1 AND @objDate2))" + str;
					}
					SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
					while (sqlDataReader.Read())
					{
						double num = double.Parse(sqlDataReader["numMaxBalancer"].ToString()) - (double.Parse(sqlDataReader["numFirstBalancer"].ToString()) + double.Parse(sqlDataReader["InputInTime"].ToString()) - double.Parse(sqlDataReader["OutputInTime"].ToString()));
						if (num < 0.0)
						{
							num = 0.0;
						}
						this.objTable.Rows.Add(new object[]
						{
							sqlDataReader["ProductName"].ToString(),
							sqlDataReader["productUnit"].ToString(),
							sqlDataReader["numFirstBalancer"].ToString(),
							sqlDataReader["InputInTime"].ToString(),
							double.Parse(sqlDataReader["numFirstBalancer"].ToString()) + double.Parse(sqlDataReader["InputInTime"].ToString()),
							sqlDataReader["OutputInTime"].ToString(),
							"0",
							double.Parse(sqlDataReader["numFirstBalancer"].ToString()) + double.Parse(sqlDataReader["InputInTime"].ToString()) - double.Parse(sqlDataReader["OutputInTime"].ToString()),
							num.ToString()
						});
					}
					sqlDataReader.Close();
					sqlConnection.Close();
					sqlConnection.Dispose();
					this.btnPrint.Enabled = true;
					this.dgvProduct.DataSource = this.objTable;
					if (this.objTable.Rows.Count > 0)
					{
						this.lblMsg.Visible = false;
						this.btnMakePlan.Enabled = true;
					}
					else
					{
						this.lblMsg.Visible = true;
						this.btnMakePlan.Enabled = false;
					}
				}
				thread.Abort();
			}
			catch
			{
				this.btnPrint.Enabled = false;
				this.btnExportToExcel.Enabled = false;
				this.objTable = null;
				this.dgvProduct.DataSource = this.objTable;
			}
		}
		private void txtfromDay_ValueChanged(object sender, EventArgs e)
		{
			this.getData();
		}
		private void txttoDay_ValueChanged(object sender, EventArgs e)
		{
			this.getData();
		}
		private void cbbWareHouse_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.isPostback)
			{
				this.getData();
			}
		}
		private void txtSearch_TextChanged(object sender, EventArgs e)
		{
			if (this.isPostback)
			{
				this.getData();
			}
		}
		private void showWatting()
		{
			try
			{
				this.objW = new frmWaitting();
				this.objW.ShowDialog();
				Thread.Sleep(40);
			}
			catch
			{
			}
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
			frmBookGPPView frmBookGPPView = new frmBookGPPView();
			frmBookGPPView.objectName = "FocusMind";
			frmFocusMindPrint.objTable = this.objTable;
			frmBookGPPView.ShowDialog();
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmFocusMindPrint.objTable = new DataTable();
				frmFocusMindPrint.objTable = this.objTable;
				ActiveReport3 activeReport = new frmFocusMindPrint();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			frmSavePlan frmSavePlan = new frmSavePlan();
			frmSavePlan.objTable = this.objTable;
			frmSavePlan.ShowDialog();
			this.dgvProduct.ReadOnly = true;
			this.btnSave.Enabled = false;
			this.btnMakePlan.Enabled = true;
			if (frmSavePlan.saved)
			{
				this.getListPlan();
			}
		}
		private void btnMakePlan_Click(object sender, EventArgs e)
		{
			this.dgvProduct.ReadOnly = false;
			this.btnSave.Enabled = true;
			this.btnMakePlan.Enabled = false;
		}
		private void dgvListPlan_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.currPlanID = this.dgvListPlan.Rows[e.RowIndex].Cells[1].Value.ToString();
				this.getListPlanDetail(this.currPlanID);
			}
			catch
			{
			}
		}
		private void mnuDel_Click(object sender, EventArgs e)
		{
			try
			{
				if (MessageBox.Show("Bạn có chắc chắn muốn xoá mục này không?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					this.detListPlan(this.currPlanID);
					this.getListPlan();
				}
			}
			catch
			{
			}
		}
	}
}
